<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="输入您要搜索的名称"
        v-model="keywords"
        @keyup.enter="search($event)"
      />&nbsp;<button @click="search($event)">Search</button>
    </div>
  </section>
</template>
<script>
import axios from 'axios';
export default {
  name: "Search",
  data() {
    return {
      keywords: "",
      data:''
    };
  },
  methods: {
    search(e) {
      this.data = this.keywords;
      this.keywords = "";
      e.target.blur();
      this.$bus.$emit("getList", {
        isWelcome: false,
        isLoading: true,
        errorMsg: "",
      });
      axios.get(`https://api.github.com/search/users?q=${this.data}`).then(
        (res) => {
          console.log(res);
          this.$bus.$emit("getList", {
            dataList: res.data.items,
            isLoading: false,
            errorMsg: "",
          });
        },
        (err) => {
          this.$bus.$emit("getList", {
            isLoading: false,
            errorMsg: err.message,
          });
        }
      );
    },
  },
};
</script>
<style scoped>
</style>